package com.example.automanagement.controller;

import com.example.automanagement.entity.BusinessMenu;
import com.example.automanagement.service.BusinessMenuService;
import com.example.automanagement.util.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class BusinessMenuController {
    @Autowired
    private BusinessMenuService businessMenuService;

    @GetMapping(value="/getBusinessMenu")
    public Result getBusinessMenu(){
        try {
            List<BusinessMenu> businessMenuList = businessMenuService.getBusinessMenu();
            return Result.success(businessMenuList,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }

    @PostMapping(value = "/addBusinessMenu")
    public Result addBusinessMenu(BusinessMenu businessMenu){
        try{
            businessMenuService.addBusinessMenu(businessMenu);
            return Result.success("新增成功");
        } catch (Exception e) {
            return Result.error("500","新增失败！");
        }
    }

    @PutMapping(value = "/updateBusinessMenu")
    public Result updateBusinessMenu(BusinessMenu businessMenu){
        try {
            businessMenuService.updateBusinessMenu(businessMenu);
            return Result.success("修改成功");
        } catch (Exception e) {
            return Result.error("500","修改失败！");
        }

    }


    @DeleteMapping(value = "/deleteBusinessMenu")
    public Result deleteBusinessMenu(@RequestParam("businessIdDelete") int businessId){
        try {
            businessMenuService.deleteBusinessMenu(businessId);
            return Result.success("删除成功");
        } catch (Exception e) {
            return Result.error("500","删除失败");
        }
    }

}
